class Solution {
public:
    double findMaxAverage(vector<int>& nums, int k) {
        if(!k)return 0;
        double avg = 0.0;
        long long sum = 0;
        int i = 0, j = 0;
        for(; i < k; i++)sum += nums[i];
        avg = double(sum) / k;
        sum -= nums[j++];
        for(; i < nums.size(); i++){
            sum += nums[i];
            avg = max(avg, double(sum) / k);
            sum -= nums[j++];
        }
        return avg;
    }
};

//2021.2.4 
